/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package bmp.dao;

import bmp.common.Constant;
import bmp.object.SinhVienOBJ;
import java.io.Serializable;
import java.sql.CallableStatement;
import java.sql.SQLException;

/**
 *
 * @author Admin
 */
public class SinhVienDAO implements Serializable {

    /*
     * Return type: ID of student
     */
    public static int insertSinhVien(SinhVienOBJ sinhVien){

        ConnectDB connectDB=ConnectDB.getConnectDB();
        
        try{
            CallableStatement csmt=connectDB.getConnection()
                    .prepareCall("{call sp_insert_sinhvien(?,?,?,?)}");
            csmt.registerOutParameter("ID",java.sql.Types.INTEGER);
            csmt.setNString("name",sinhVien.getName());
            csmt.setNString("address",sinhVien.getAddress());
            csmt.setNString("phone",sinhVien.getPhone());
            csmt.execute();
            if(csmt.getInt("ID")!=Constant.FALSE_ID){
                return csmt.getInt("ID");
            }
            
        }
        catch(SQLException ex){
            ex.printStackTrace();
        }
        finally{
            connectDB.closeConnect();
        }
        return Constant.FALSE_ID;
    }

}
